package kechengsheji.admin;

import Main.Login;
import Main.MainJFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Adminpanel extends JPanel {
    private static JDesktopPane contentpanel = new JDesktopPane();

    public Adminpanel() {
        this.setBounds(0,0,800,600);
        this.setLayout(new BorderLayout());
        this.setVisible(true);

        JMenuBar menuBar = new JMenuBar();//菜单容器
        menuBar.setBounds(0,0,800,50);//菜单栏
        this.add(menuBar,BorderLayout.NORTH);//上

        contentpanel.removeAll();
        contentpanel.repaint();
        this.add(contentpanel,BorderLayout.CENTER);//中

        JMenu parentmenu = new JMenu("会议室管理");
        parentmenu.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                setContent(new AdminTablePanel());
            }
        });

        JMenu logoutMenu = new JMenu("退出登录");
        menuBar.add(parentmenu);
        menuBar.add(logoutMenu);

        logoutMenu.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                contentpanel.removeAll();
                contentpanel.repaint();
                try {
                    MainJFrame.setContent(new Login());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }

    public static void setContent(JInternalFrame internalFrame) {
        internalFrame.setSize(885,540);
        internalFrame.setVisible(true);
        contentpanel.removeAll();
        contentpanel.repaint();
        contentpanel.add(internalFrame);
    }
}
